'use strict';
const requireEx =require('yi-require');

const middleware =(req, res, next)=>{
    let doc = req.body;
    req.mongo.collection('goodsType').find({storeId:doc.storeId}).count((e0,r0)=>{
        if(e0) return res.err.mongoError(e0);
        doc.sort = r0+1;
        next();
    });
};

module.exports = {
    open:false,
    middleware:middleware,
    description:'新增商品类型',
    handler:requireEx('yi-restful').c('goodsType',[])
};
